﻿using System.Drawing;
using WeForms.Drawing;

namespace WeForms.Controls
{
    internal class RadioButtonGroupRenderer
    {
        public static void PaintItem(RadioButtonGroup parent, object item, Graphics graphics, Rectangle bounds, int index)
        {
            //
            // Background
            //
            ControlPaintHelper background = parent.SelectedIndex == index
                                                ? TouchButtonRenderer.ButtonPainter[(int)parent.SelectedColorScheme]
                                                : TouchButtonRenderer.ButtonPainter[(int)parent.UnselectedColorScheme];
            ControlParts neededParts = ControlParts.Top | ControlParts.Content | ControlParts.Bottom;

            // Is First?  
            if (index == 0)
            {
                // Add Left Edges
                neededParts |= (ControlParts.TopLeft | ControlParts.CenterLeft | ControlParts.BottomLeft);
            }
            // Is Last?  
            if (index == parent.Items.Count - 1)
            {
                // Add Right Edges
                neededParts |= (ControlParts.TopRight | ControlParts.CenterRight | ControlParts.BottomRight);
            }

            // draw background
            int drawIndex = index == parent.SelectedIndex ? 2 : 0;
            background.Draw(graphics, bounds, drawIndex, neededParts);

            //
            // Caption
            //
            Brush caption = parent.SelectedIndex == index
                    ? TouchButtonRenderer.CaptionBrush[(int)parent.SelectedColorScheme]
                    : TouchButtonRenderer.CaptionBrush[(int)parent.UnselectedColorScheme];
            string text = parent.GetItemText(item);
            graphics.DrawString(text, parent.Font, caption, bounds, TouchButtonRenderer.CaptionFormat);

        }
    }
}
